package com.core.dao.mybatismysql;

import com.core.bean.Category;
import com.core.dao.ICategoryDao;
import com.core.utils.MybatisUtils;
import org.apache.ibatis.session.SqlSession;


public class CategoryDao implements ICategoryDao {


    @Override
    public int add(Category entity) throws Exception {
        SqlSession session = MybatisUtils.getSession();
        ICategoryDao mapper = session.getMapper(ICategoryDao.class);
        int add = mapper.add(entity);
        return add ;
    }

    @Override
    public int remove(String id) throws Exception {
        SqlSession session = MybatisUtils.getSession();
        ICategoryDao mapper = session.getMapper(ICategoryDao.class);
        int remove = mapper.remove(id);

        return remove;
    }

    @Override
    public int modify(Category entity) throws Exception {
        SqlSession session = MybatisUtils.getSession();
        ICategoryDao mapper = session.getMapper(ICategoryDao.class);
        int modify = mapper.modify(entity);
        return modify;
    }

    @Override
    public Category findEntityById(String id) throws Exception {
        SqlSession session = MybatisUtils.getSession();
        ICategoryDao mapper = session.getMapper(ICategoryDao.class);
        Category entityById = mapper.findEntityById(id);
        return entityById;
    }

    @Override
    public Category queryByName(String name) {
        SqlSession session = MybatisUtils.getSession();
        ICategoryDao mapper = session.getMapper(ICategoryDao.class);
        Category category = mapper.queryByName(name);
        return category;
    }
}
